package com.igeek.collateral.controller;

import com.igeek.collateral.entity.Cstatus;
import com.igeek.collateral.result.Result;
import com.igeek.collateral.service.ICstatusService;
import com.igeek.collateral.vo.StatusVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import liquibase.pro.packaged.E;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * TODO
 *
 * @author chh
 * @since 2024/7/24
 **/
@RestController
@RequestMapping("/admin/cstatus")
@Api(tags = "状态历史流程接口")
@Slf4j
public class CstatusController {

    @Autowired
    private ICstatusService iCstatusService;
    //每次改变状态后,像状态流程表中加入一条信息
    @PostMapping("add")
    @ApiOperation("插入状态信息")
    public Result add(@RequestParam("collateralId") int collateralId)
    {
        try {
            boolean save = iCstatusService.addNew(collateralId);
            if(save)
            {
                return new Result(true,"添加成功");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new Result(false,"添加失败");
    }



    //点击详情的时候能够查询到，当前押品的状态流转
    @GetMapping("historyStatus")
    @ApiOperation("查询当前押品的历史状态的流转")
    public  Result findAllStatus(@RequestParam("collateralId") Long collateralId)
    {
        try{
            List<StatusVo> list = iCstatusService.findAllMess(collateralId);
            if(!ObjectUtils.isEmpty(list))
            {
                return new Result(true,"查询成功",list);
            }
        }catch (Exception e)
        {
            e.printStackTrace();
        }
        return new Result(false,"查询失败");
    }
}
